﻿using DisconfClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Formatting;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Ymatou.CommonService;
using Ymatou.Evaluate.Common;
using Ymatou.ServiceCenter;

namespace BuyerEvaluateQuery.Api
{
    public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {

            log4net.Config.XmlConfigurator.Configure();

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
            GlobalConfiguration.Configuration.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("json", "true", "application/json"));

            UnityConfig.RegisterComponents();
            try
            {
                ConfigManager.Init(assemblies: typeof(EvaluateConfig).Assembly);   //DisconfClient初始化
            }
            catch (Exception ex)
            {
                ApplicationLog.Error(string.Format("Disconf初始化异常：{0}", ex.Message), ex);
            }
            try
            {
                ServiceRegisterManager.InitRpc();
            }
            catch (Exception ex)
            {
                ApplicationLog.Error(string.Format("RPC初始化异常：{0}", ex.Message), ex);
            }
        }
    }
}
